# 员工考勤与绩效管理系统
class Device:
    def __init__(self, name):
        self.name = name
        self.status = False

    def turn_on(self):
        self.status = True
        return f'{self.name} 开启'

    def turn_off(self):
        self.status = False
        return f'{self.name} 关闭'

    def get_status(self):
        return '开启' if self.status else '关闭'
    def check_status(self, flag):
        if flag == self.status:
            return f'{self.name} 处于预期状态'
        else:
            return f'{self.name} 不处于预期状态'

class Light(Device):
    def __init__(self, name):
        super().__init__(name)


class AirConditioner(Device):
    def __init__(self, name, temperature):
        super().__init__(name)
        self.temperature = temperature

    def set_temperature(self, temperature):
        if self.status:
            self.temperature = temperature
            return f'设置成功'
        else:
            return f'空调未开启'


class DoorLock(Device):
    def __init__(self, name, password):
        super().__init__(name)
        self.password = password

    def turn_off(self, password):
        if self.password == password:
            super().turn_off()
            return f'{self.name}解锁成功'
        else:
            return '密码错误'
    def turn_on(self):
        super().turn_on()
        return f'{self.name}上锁成功'

class Camera(Device):
    def __init__(self, name):
        super().__init__(name)
        self.window_status = False
        self.door_status = False

    def door_window_status(self):  # 添加状态检测方法
        return (f'{self.name}监控状态: '
                f'门{"开" if self.door_status else "关"}, '
                f'窗{"开" if self.window_status else "关"}')

    def update_window_status(self, status):
        self.window_status = status
        return f'{self.name} 窗户状态已更新为{"打开" if status else "关闭"}'
    def update_door_status(self, status):
        self.door_status = status
        return f'{self.name} 门状态已更新为{"打开" if status else "关闭"}'

class System():
    def __init__(self):
        self.devices = {}  # 用字典存储设备，键为设备名称，值为设备对象
        self.device_types = {
            'light': Light,
            'airconditioner': AirConditioner,
            'doorlock': DoorLock,
            'camera': Camera
        }

    def add_device(self, device_type, name, data):
        if name in self.devices:
            return f"设备 {name} 已存在"

        device_type = device_type.lower()
        if device_type not in self.device_types:
            return f"不支持的设备类型: {device_type}"

        try:
            if device_type == 'light' or device_type == 'camera':
                device = self.device_types[device_type](name)
            else:
                device = self.device_types[device_type](name, data)
            self.devices[name] = device
            return f"已添加设备: {name}"
        except Exception as e:
            return f"添加设备失败: {str(e)}"

    def list_devices(self):
        if not self.devices:
            return "没有已添加的设备"

        result = "已连接设备列表:\n"
        for device in self.devices.keys():
            result += f"- {device}\n"
        return result.strip()


if __name__ == '__main__':
    control_center = System()
    print(control_center.add_device("light", "客厅灯",None))
    print(control_center.add_device("airconditioner", "卧室空调", 24))
    print(control_center.add_device("doorlock", "前门", "123456"))
    print(control_center.add_device("camera", "客厅摄像头",None))
    print(control_center.list_devices())
    print(control_center.devices.keys())
    print(control_center.devices['客厅灯'].check_status(True))
    print(control_center.devices['卧室空调'].set_temperature(16))
    print(control_center.devices['前门'].turn_off('123456'))
    print(control_center.devices['客厅摄像头'].door_window_status())